package com.sky.mapper;

import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    List<SetmealVO> queryPage(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 插入套餐基础 数据
     * @param setmeal
     */
    @Insert("        insert into setmeal (category_id, name, price, status, description, image, create_time, update_time, create_user, update_user)values (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    void insertSetmeal(Setmeal setmeal);

    /**
     * 根据id查询套餐数据
     * @param id
     * @return
     */

    SetmealVO getSetmealById(Long id);

    /**
     * 修改套餐数据
     * @param setmeal
     */
    void updateSetmeal(Setmeal setmeal);

    /**
     * 更新单个套餐的状态
     * @param setmeal
     */
    void updateStatus(Setmeal setmeal);

    /**
     * 统计起售状态的套餐数量（用于校验）
     * @param status
     * @param ids
     * @return
     */
    Integer countByStatusAndIds(@Param("status") Integer status, @Param("ids") List<Long> ids);

    /**
     * 批量删除套餐基础数据
     * @param ids 套餐ID列表
     */
    void deleteBatch(@Param("ids") List<Long> ids);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
